package com.yb.core.util;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Component;
import org.springframework.util.ResourceUtils;

import java.io.IOException;
import java.io.InputStream;

/**
 * Copyright (C), 2022-2023, 姚兵
 * Author: 32210
 * Date: 2023/5/9 13:29
 * FileName: ResourceUtil
 * Description:
 */

@Slf4j
public class ResourceUtil {

    private static ResourceLoader resourceLoader=new DefaultResourceLoader();


    /**
     * 不需要家classpath前缀
     * @param classpathResourceName
     * @return
     */

    public static String loadResourceAsString(String classpathResourceName){

        Resource resource = resourceLoader.getResource(ResourceUtils.CLASSPATH_URL_PREFIX + classpathResourceName);

        String  result = IOUtil.toString(resource);

        return result;
    }
}
